using System;
using NUnit.Framework;
using RMH.DataAccess;
using RMH.Entities;
using RMH.Web;
using RMH.UnitTests;

namespace RMH.IntegrationTests.Repository
{
    [TestFixture]
    public class StaffRepositorySpecs_can_persist : RepositoryBaseSpecs
    {
        Staff staff = new Staff { Email = "len@divide0.net", Password = "12", UserName = "ignu" };
        Staff returnedStaff = new Staff();
        private StaffRepository staffRepository = Container.Resolve<StaffRepository>();
        private StaffRole role = new StaffRole { Name = "Hello" };

        public override void because()
        {
            Container.Resolve<StaffRoleRepository>().Save(role);
            
            staffRepository.Save(staff);
            staffRepository.Flush();
            staff.Roles.Add(role);
            staffRepository.Flush();
            staffRepository.Clear();
            returnedStaff = staffRepository.GetByID(staff.Id);
        }

        [Test]
        public void all_properties_are_persisted()
        {
            returnedStaff.Password.ShouldEqual(staff.Password);
            returnedStaff.Email.ShouldEqual(staff.Email);
            returnedStaff.UserName.ShouldEqual(staff.UserName);
        }

        [Test]
        public void roles_are_persisted()
        {
            returnedStaff.Roles.ShouldContain(role);
            role.Name.ShouldEqual("Hello");
        }
    }
}